import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;

import java.util.*;

public class Generate {
  public static void main(String[] args) {
    final Scanner scanner = new Scanner(System.in);
    System.out.println("输入表名，多表逗号隔开:");
    final String tableStr = scanner.next();
    final List<String> tables = new ArrayList<>(Arrays.asList(tableStr.split(",")));
    FastAutoGenerator.create(
            "jdbc:mysql://dev:3306/jwpj?useunicode=true&characterencoding=utf8&servertimezone=utc",
            "root",
            "root")
        .globalConfig(
            builder -> {
              builder
                  .author("lp") // 作者
                  .outputDir(System.getProperty("user.dir") + "/src/main/java") // 输出路径(写到java目录)
                  .enableSwagger() // 开启swagger
                  .fileOverride()
                  .commentDate("yyyy-MM-dd"); // 开启覆盖之前生成的文件
            })
        .packageConfig(
            builder ->
                builder
                    .parent("com.example")
                    .moduleName("teachingevaluationsystem")
                    .entity("entity")
                    .service("service")
                    .serviceImpl("service.impl")
                    .controller("controller")
                    .mapper("mapper")
                    .xml("mapper")
                    .pathInfo(
                        Collections.singletonMap(
                            OutputFile.xml,
                            System.getProperty("user.dir") + "/src/main/resources/mapper")))
        .strategyConfig(
            builder ->
                builder
                    .addInclude(tables)
                    .serviceBuilder()
                    .formatServiceFileName("%sService")
                    .formatServiceImplFileName("%sServiceImpl")
                    .entityBuilder()
                    .enableLombok()
                    .enableTableFieldAnnotation()
                    .addSuperEntityColumns("tenant_id", "created_time", "updated_time")
                    .controllerBuilder()
                    .formatFileName("%sController")
                    .enableRestStyle()
                    .mapperBuilder()
                    .superClass(BaseMapper.class)
                    .formatMapperFileName("%sMapper")
                    .enableMapperAnnotation()
                    .formatXmlFileName("%sMapper"))
        // 使用Freemarker引擎模板，默认的是Velocity引擎模板
        .execute();
  }
}
